package org.hwadee.interceptor;

import org.hwadee.entity.User;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class LoginInterceptor implements HandlerInterceptor {

    //    @Override
//    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//        //登陆和注册页面不需要判断即可跳转，所以需要过滤请求路径
//        String uri = request.getRequestURI();
////        System.out.println(uri);
//        if (uri.endsWith("/") ||
//                uri.endsWith("/page/common/login") ||
//                uri.endsWith("/page/login") ||
//                uri.endsWith("login.jsp") ||
//                uri.endsWith("/user/login") ||
//                uri.endsWith("/manage/manageLogin") ||
//                uri.endsWith("/page/register") ||
//                uri.endsWith("/page/common/register") ||
//                uri.endsWith("/user/register"))
//            return true;
//        else if (uri.contains("/js/") ||
//                uri.contains("/css/") ||
//                uri.contains("/image/"))
//            return true;
//
//        User user = (User) request.getSession().getAttribute("user");
//        if (user != null)
//            return true;
//
//        request.getRequestDispatcher("/login.jsp").forward(request, response);
////        response.sendRedirect("/login.jsp");
//        return false;
//    }
}
